<template>
    <StElUpload
            ref="stelupload"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
        <el-avatar :size="60" :src="imageUrl">
            {{(imageUrl) ? '加载失败':'请上传'}}
        </el-avatar>
    </StElUpload>
</template>

<script>
    export default {
        name: 'StElUploadAvatar',
        props:{
            value: String
        },
        data() {
            return {
                imageUrl: this.value,
            };
        },
        methods: {
            handleAvatarSuccess(res, file) {
                this.imageUrl = res.url
                this.$emit('input',this.imageUrl)
                this.$emit('data',res)
            },
            beforeAvatarUpload(file) {

            }
        },
        watch:{
            value(val, oldVal) {
                this.imageUrl = val
            }
        }
    }
</script>
